package com.project.service.impl;

import com.project.bean.UseBean;
import com.project.mapper.IUseMapper;
import com.project.service.IUseService;
import org.apache.ibatis.session.SqlSession;

public class UseServiceImpl extends BaseService implements IUseService {
    @Override
    public void addUse(UseBean useBean, int[] gradeArray) {
        SqlSession session = this.getSession();
        IUseMapper mapper = session.getMapper(IUseMapper.class);
        mapper.addUse(useBean);
        mapper.addCenter(useBean.getUseID(), gradeArray);
        session.commit();
        session.close();
    }

    @Override
    public void delUse(int useID) {
        SqlSession session = this.getSession();
        IUseMapper mapper = session.getMapper(IUseMapper.class);
        mapper.delUse(useID);
        session.commit();
        session.close();
    }

    @Override
    public void updateUseGrade(int useID, int[] gradeArray) {
        SqlSession session = this.getSession();
        IUseMapper mapper = session.getMapper(IUseMapper.class);
        mapper.updateUseGrade(useID,gradeArray);
        session.commit();
        session.close();
    }

    @Override
    public UseBean fondById(int useID) {
        SqlSession session = this.getSession();
        IUseMapper mapper = session.getMapper(IUseMapper.class);
        UseBean use=mapper.fondById(useID);
        session.close();
        return use;
    }
}
